package com.jt.safe.ui.parent.activity

import android.graphics.drawable.ColorDrawable
import android.view.ViewGroup
import android.widget.PopupWindow
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.jt.safe.R
import com.jt.safe.base.BaseActivity
import com.jt.safe.entity.BindingStudentPoBean
import com.jt.safe.ui.adpter.BindingStudentPoAdapter
import com.jt.safe.viewmodel.NullViewModel
import com.orhanobut.logger.Logger
import kotlinx.android.synthetic.main.activity_binding_student.*
import kotlinx.android.synthetic.main.title_bar_layout.*

class BindingStudentActivity : BaseActivity<NullViewModel>() {

    val schools = mutableListOf<BindingStudentPoBean>()
    override val layoutId: Int
        get() = R.layout.activity_binding_student

    override fun initView() {
        title_tv.text = "绑定学生"
        val popupWindow = PopupWindow()
        popupWindow.contentView = layoutInflater.inflate(R.layout.select_popu, null, false)
        popupWindow.width = ViewGroup.LayoutParams.MATCH_PARENT
        popupWindow.height = ViewGroup.LayoutParams.WRAP_CONTENT
        popupWindow.setBackgroundDrawable(ColorDrawable(0x00000000))
        popupWindow.isFocusable = true
        val recycler = popupWindow.contentView.findViewById<RecyclerView>(R.id.recycler)
        recycler.layoutManager = LinearLayoutManager(this)
        val bindingStudentPoAdapter = BindingStudentPoAdapter()
        recycler.adapter = bindingStudentPoAdapter
        ll_x.setOnClickListener {
            Logger.d("show1")
            popupWindow.showAsDropDown(ll_x, 0, 0)
            schools.clear()
            schools.add(BindingStudentPoBean("曲江三小", true))
            schools.add(BindingStudentPoBean("曲江二小", false))
            schools.add(BindingStudentPoBean("曲江一小", false))
            bindingStudentPoAdapter.setNewData(schools)
        }
        ll_n.setOnClickListener {
            popupWindow.showAsDropDown(ll_n, 0, 0)
            schools.clear()
            schools.add(BindingStudentPoBean("三年级", true))
            schools.add(BindingStudentPoBean("二年级", false))
            schools.add(BindingStudentPoBean("一年级", false))
            bindingStudentPoAdapter.setNewData(schools)
        }
        ll_b.setOnClickListener {
            popupWindow.showAsDropDown(ll_b, 0, 0)
            schools.clear()
            schools.add(BindingStudentPoBean("三班", true))
            schools.add(BindingStudentPoBean("二班", false))
            schools.add(BindingStudentPoBean("一班", false))
            bindingStudentPoAdapter.setNewData(schools)
        }
        popupWindow.setOnDismissListener {
            Logger.d("dismiss")
        }
    }

    override fun createObserver() {

    }
}
